package com.handtransaction.service.impl;

import com.handtransaction.dao.GoodsDao;
import com.handtransaction.dao.OrderDao;
import com.handtransaction.dao.UserDao;
import com.handtransaction.entity.Goods;
import com.handtransaction.entity.Order;
import com.handtransaction.entity.User;
import com.handtransaction.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

/**
 * @author YAO
 * @create 2021-04-04 0:26
 */
@Service
public class OrderServiceImpl implements OrderService {

    @Autowired
    OrderDao orderDao;

    @Autowired
    GoodsDao goodsDao;

    @Autowired
    UserDao userDao;

    @Override
    public void createOrder(Goods goods,Integer obid) {
////        生成订单对象

        Order order1 = new Order(null,obid,goods.getGuid(),goods.getGid(),new Date(),"已完成",1,goods.getGprice(),goods.getGname(),goods.getGdetail());
        Order order2 = new Order(null,obid,goods.getGuid(),goods.getGid(),new Date(),"已完成",1,goods.getGprice(),goods.getGname(),goods.getGdetail(),goods.getGimg_path());

        orderDao.SaveOrder(order2);
    }

    @Override
    public void createOrder2(Order order,Integer obid) {
        User user = userDao.queryUserByuid(obid);
        orderDao.SaveOrder2(order);
    }

    @Override
    public List<Order> searchOrdersByobid(Integer obid) {

        return orderDao.searchOrdersByobid(obid);
    }

    @Override
    public List<Order> searchOrdersByosid(Integer osid) {
        return orderDao.searchOrdersByosid(osid);
    }

    @Override
    public void deleteorder(Integer oid) {
        orderDao.deleteSingleOrder(oid);
    }


    /**
     *  管理员对订单的操作
     */
    @Override
    public int deleteOrderByAdmin(Integer oid) {
        return orderDao.deleteOrderByAdmin(oid);
    }

    @Override
    public Order queryOrderByAdminByOid(Integer oid) {
        return orderDao.queryOrderByAdminByOid(oid);
    }

    @Override
    public List<Order> queryOrderByAdminByObid(Integer obid) {
        return orderDao.queryOrderByAdminByObid(obid);
    }

    @Override
    public List<Order> queryOrderByAdminByOsid(Integer osid) {
        return orderDao.queryOrderByAdminByOsid(osid);
    }

    @Override
    public List<Order> queryOrderByAdminByUserId(Integer uid) {
        return orderDao.queryOrderByAdminByUserId(uid);
    }

    @Override
    public List<Order> queryAllOrder() {
        return orderDao.queryAllOrder();
    }

    @Override
    public BigDecimal showTransactionAmount() {
        return orderDao.sumTransactionAmount();
    }
}
